﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Engine.IA.Sensor;
using Engine.IA.Atuadores;
using Engine.SceneControl;

namespace Engine.IA.Steering
{
    public class BehaviorsHandler
    {

        public BehaviorsHandler(IObject obj)
        {
            actuator = new DirectionActuator(obj);
            actsensor = new ActuatorsResponsesSensor();                        
            actuator.Attach(actsensor);            

        }        
        DirectionActuator actuator;
        ActuatorsResponsesSensor actsensor;
        private List<ISteeringBehavior> steeringBehaviors = new List<ISteeringBehavior>();
        private SteeringInfoInput input;

        public SteeringInfoInput Input
        {
            get { return input; }
            set { input = value; }
        }

        public List<ISteeringBehavior> SteeringBehaviors
        {
            get { return steeringBehaviors; }
            set { steeringBehaviors = value; }
        }

        public void Update()
        {
            IDictionary<String, ActuatorSensorInformation> resp = actsensor.DetectEnviroment();
            input.ActuatorsSensorInformations = resp;

            Vector3 dir = Vector3.Zero;
            foreach (ISteeringBehavior item in steeringBehaviors)
            {
                SteeringInfoOutput op = item.Perform(input);
                dir += op.Direction;
            }
            actuator.SetDirection(dir);
            actuator.Actuate();

        }
    }
}
